package com.heima.admin.job;

import com.heima.admin.feign.WemediaFeign;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @作者 itcast
 * @创建日期 2021/2/1 10:40
 **/
@Component
@Slf4j
public class WeMediaNewsAutoScanJob {

    @Autowired
    WemediaFeign wemediaFeign;

    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @XxlJob("wemediaAutoScanJob")
    public ReturnT newsAutoScanJob(String params){
        log.info("定时发布文章任务被触发====> start");
        // 基于feign远程调用wemedia中的findRelease方法查询出所有需要发布的文章Id
        // 状态为(4 或 8)并且发布时间小于等于当前
        List<Integer> newsIdList = wemediaFeign.findRelease();
        //遍历文章id列表，调用文章发布方法
        if(newsIdList!=null && !newsIdList.isEmpty()){
            for (Integer newsId : newsIdList) {
                wemediaNewsAutoScanService.autoScanByMediaNewsId(newsId);
            }
        }
        log.info("自媒体文章审核调度任务执行结束....");
        return ReturnT.SUCCESS;
    }


}
